const mongoose = require('mongoose');

const studentSchema = new mongoose.Schema({
    name: {
        type: String,
        required: true,
        minlength: 2,
        maxlength: 10
    },
    age: {
        type: Number,
        min: 0,
        max: 100,
        default: 0
    },
    sex: {
        type: String,
        enum: ['0', '1', '2'], // 0未知  1男  2女
        default: '0'
    },
    email: {
        type: String,
        validator(v) {  // 验证邮箱
            return /^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/.test(v)
        },
        message: 'email verify faild.'
    },
    hobbies: [String],
    collage: String,
    enterDate: {
        type: Date,
        default: Date.now
    }
})

const Student = mongoose.model('Student', studentSchema, 'Student');
// console.log('Student集合创建成功');

module.exports = {
    Student
}